#include "callbacks.h"
#include "widgets.h"
#include "client.h"

void on_mainWindow_destroy(GtkWindow * window) {
	gtk_main_quit();
}

void on_menuAbout_activate(GtkWindow * window) {
	//const gchar * artists[] = { "filecorpse" };
	//GtkAboutDialog * about = (GtkAboutDialog *)gtk_about_dialog_new();
	//gtk_about_dialog_set_artists(about, artists);
	const gchar *authors[] = { "filecorpse <filecorpse@gmail.com>",	NULL };
	gtk_show_about_dialog(GTK_WINDOW(mainWindow),
			"name", _("Slimp"),
			"version", "0.0.1",
			"copyright", _("Copyright 2008 filecorpse"),
			"comments", _("Stegano LAN instant messenger program"),
			"license", "GPL",
			"authors", authors,
			NULL);
}

void on_userView_row_activated(GtkWindow * window) {
	gtk_widget_show(chatWindow);
	gtk_window_set_focus(GTK_WINDOW(chatWindow), GTK_WIDGET(outgoingText));
}

void on_outgoingText_key_release_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
	if((event->keyval == gdk_keyval_from_name("Return")) || (event->keyval == gdk_keyval_from_name("KP_Enter"))) {
		//GtkTextIter start, end;
		GtkTextIter start;
		GtkTextIter end;
		//pthread_t client_thread;
		gtk_text_buffer_get_start_iter (outgoingText->buffer, &start);
		gtk_text_buffer_get_end_iter (outgoingText->buffer, &end);
		gchar * message = gtk_text_buffer_get_text(outgoingText->buffer, &start, &end,0);
		add_message(message, (gchar *)g_get_user_name());
		gtk_text_buffer_set_text(outgoingText->buffer,"", -1);
		sendMessage_t * m;
		m->ip = "127.0.0.1";
		//m->message = message;
		gsize in;
		gsize out;
		in = strlen(message) + 1;
		out = 0;
		m->message = message;//g_locale_from_utf8(message, -1, NULL, NULL, NULL);
		//g_print("(CALLBACK)%s\n", m->message);
		init_client(m);
		//g_free(message);
		//g_free(m);
	}
	//printf("keyname: %s\n",gdk_keyval_name(event->keyval));
}
